<template>
  <div id="courselist"> 

          <el-table :data="datalist" style="width: 100%" :height="dtheight" :header-cell-style="{background:'#4F81BC',color:'white'}"
           :row-class-name="tableRowClassName"  :border="true">

                <el-table-column label="Logo"  align='center' >                   
                    <template slot-scope="scope">                   
                       <img  style="width: 30px; height: 30px" :src="urlimg + scope.row.icon" /> 
                    </template>
                </el-table-column>
                <el-table-column label="名称"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.name }}</span>
                    </template>
                </el-table-column>  
                 <el-table-column label="英文名称"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.ename }}</span>
                    </template>
                </el-table-column>   
                <el-table-column :label="variable_name2 + '数量' "  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.give_number }}</span>
                    </template>
                </el-table-column>

                 <el-table-column label="操作" align='center' width="300px">
                    <template slot-scope="scope"> 
                        <el-button size="mini"  type="primary" class="button_class1"  plain @click="go_but(scope.row)">内容</el-button>
                        <el-button size="mini"  type="primary" class="button_class2"  plain @click="xg_but(scope.row)">修改</el-button> 
                        <el-button size="mini"  type="primary" class="button_class1" plain @click="delete_but(scope.row)">删除</el-button> 
                    </template>
                </el-table-column>        

  
            </el-table>  



    <!-- 修改内容 -->
    <el-dialog title="修改内容" :visible.sync="xg_mtk"  width="600px">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="70px" style="width:100%;">
    
             <el-form-item label="中文标题">
                    <el-input    v-model="mtk_form.title" placeholder="中文标题"></el-input>
              </el-form-item> 
              <el-form-item label="英文标题">
                    <el-input    v-model="mtk_form.entitle" placeholder="英文标题"></el-input>
              </el-form-item> 
              <el-form-item :label="variable_name2 + '数量'">
                    <el-input    v-model="mtk_form.give_number" :placeholder="variable_name2 + '数量'"></el-input>
              </el-form-item> 

               <el-row style="width:100%;">
                     <el-col :span="12">
                        <el-form-item label="Logo">
                            <el-upload 
                                  action="uploadUrl"  
                                  :show-file-list="false"   
                                  :before-upload="beforeupload"
                                  :http-request="ImgUploadSectionFile">
                                  <div class="avatar-uploader">
                                      <img v-if="pic_form.head_img"  :src="pic_form.head_img" class="avatar">
                                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                  </div>
                            </el-upload>
                         </el-form-item>       
                     </el-col> 

                </el-row>                          
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="xg_but_qr">确认</el-button>
            </div>

        </div> 
    </el-dialog>




   </div>
</template>

<script>

export default {
   name: 'courselist',
   props:{
      datalist:{  
        //type:Array,
       default:()=>[]
     },
  },
  data () {
    return {
        dtheight:'500',  //窗口高度
        xg_mtk:false,
        mtk_form:{
            title:'',
            entitle:'',
            give_number:''
        },
         pic_form:{
           head_img:'',
           upfile:'',
        },
        my_study_id:'',
    }
  },
   components:{

  },
  created(){
     this.dtheight = window.innerHeight -293
      
  },
  mounted (){
    
  },
  methods: {
    xg_but(row){
        this.my_study_id = row.study_id
        this.mtk_form.title = row.name
        this.mtk_form.entitle = row.ename
        this.mtk_form.give_number = row.give_number
        this.pic_form.head_img = this.urlimg + row.icon
        this.pic_form.upfile = row.icon
        this.xg_mtk = true
    },
    xg_but_qr(){
       this.post("/study_guide/update", {
                   study_id:this.my_study_id,
                   icon:this.pic_form.upfile,
                   name:this.mtk_form.title,
                   ename:this.mtk_form.entitle,
                   give_number:this.mtk_form.give_number
                }).then(res => {

                    if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.$emit('up_list_fun')
                        this.xg_mtk = false
                        this.mtk_form={
                             title:'',
                             entitle:'',
                             give_number:''
                        }
                        this.pic_form={
                            head_img:'',
                            upfile:'',
                        }

                    }else {
                     this.open1(res.message,'warning')
                    }

              })
    },
   delete_but(row){

       this.$confirm('是否删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
         }).then(() => {

                this.post("/study_guide/delete", {
                   study_id:row.study_id
                }).then(res => {

                    if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.$emit('up_list_fun')

                    }else {
                     this.open1(res.message,'warning')
                    }
               })

        }).catch(() => {
            //  this.$emit('up_list_fun') 
        });
   
   },
     beforeupload(file){   //重新写入上穿 需要点击确认上传与表单一起提交
           if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form.head_img=windowURL.createObjectURL(file);             
            
            this.upimgpost("/image/uploadMultiple",file).then(res => {
              console.log(res.result.url )
               this.pic_form.upfile = res.result.url    
            })

            return false;
     },
      ImgUploadSectionFile(param){//图片上传    
      },
    go_but(row){
        this.$router.push({
          path: '/index/concourse',
          query: {
            name:row.name,
            id:row.study_id
          }
        })
    },


  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
</style>